package pool

import (
	"fmt"
	"database/sql"
	_ "github.com/go-sql-driver/mysql"
	"labix.org/v2/mgo"
)

var MySQL = make(chan *sql.DB, 5)
var MongoDB = make(chan *mgo.Database, 5)

func InitMySQL() {
	for i := 0; i < 5; i++ {
		db, err := sql.Open("mysql", "root:aaaa1111@tcp(127.0.0.1:3306)/ck_search?charset=utf8")
		if err != nil {
			fmt.Println("mysql connected failed", i)
		} else {
			MySQL <- db
		}
	}
}

func InitMongoDB() {
	for i := 0; i < 5; i++ {
		session, err := mgo.Dial("127.0.0.1")
        if err != nil {
        	fmt.Println("MongoDB connected failed")
        } else {
        	db := session.DB("wd")
        	MongoDB <- db
        }
	}
}
